﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DiscoveryLogic.Analytics.Modules.Entities
{
    /// <summary>
    /// Interaction logic for OrgTreeView.xaml
    /// </summary>
    public partial class OrgTreeView : UserControl
    {
        #region event
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataSetName"></param>
        public delegate void OnOrgDataSetSelected(string dataSetName);

        public event OnOrgDataSetSelected OrgDataSetSelected;
        #endregion

        #region fields
        private OrgTreePresenter _Presenter;
        #endregion

        #region ctor
        public OrgTreeView()
        {
            InitializeComponent();
        }

        public OrgTreeView(OrgTreePresenter presneter)
			: this()
		{
			_Presenter = presneter;
			_Presenter.View = this;
		}
        #endregion

        #region populate
        public void PopulateTreeView(List<string> orgDataSetNames)
        {
            this.treeOrgs.DataContext = orgDataSetNames;
        }
        #endregion

        #region selection
        private void treeOrgs_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeViewItem selectedTreeItem = e.NewValue as TreeViewItem;
            string dataSetName = (string)selectedTreeItem.Header;
            if (this.OrgDataSetSelected != null)
                this.OrgDataSetSelected(dataSetName);
        }
        #endregion
    }
}
